<?php


namespace App\HttpController;


use App\Model\UserModel;
use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Http\Message\Status;
use EasySwoole\ORM\DbManager;

class User extends Controller
{

    public function index()
    {
        $param = $this->request()->getRequestParam();
        $page  = $param['page'] ?? 1;
        $limit = $param['limit'] ?? 20;
        $model = new UserModel();
        $data  = $model->getAll($page, $param['keyword'] ?? null, $limit);
        $this->writeJson(Status::CODE_OK, $data, 'success');
    }

    public function usemysqlpool()
    {
        try {
            $connect = DbManager::getInstance()->getConnection();

        } catch (\Throwable $e) {

        }


    }

    protected function actionNotFound(?string $action)
    {
        $this->response()->withStatus(404);
        $file = EASYSWOOLE_ROOT . '/vendor/easyswoole/easyswoole/src/Resource/Http/404.html';
        if (!is_file($file)) {
            $file = EASYSWOOLE_ROOT . '/src/Resource/Http/404.html';
        }
        $this->response()->write(file_get_contents($file));
    }
}
